﻿

    using Maticsoft.BLL;
    using Maticsoft.Model;

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using Utils;
    using Wuqi.Webdiyer;

    public partial class WebPage_Tongji_Fukuan : SystemBBasePage
    {

        public Maticsoft.BLL.orderdetail detailbll = new Maticsoft.BLL.orderdetail();
        public List<Maticsoft.Model.orderdetail> detaillist = new List<Maticsoft.Model.orderdetail>();


        private int index = Convert.ToInt32(PageIndex.pageIndex);

        private Maticsoft.Model.Order order = new Maticsoft.Model.Order();
        private Maticsoft.BLL.Order orderlist = new Maticsoft.BLL.Order();
        public int pagenum = 0;
        private string sql = " 1=1 and state='pay'";
        private Maticsoft.Model.Team team = new Maticsoft.Model.Team();
        private Maticsoft.BLL.Team teamlist = new Maticsoft.BLL.Team();
        protected string today = DateTime.Now.ToString("yyyy-MM-dd");
        protected string Tommorew = DateTime.Now.AddDays(1.0).ToString("yyyy-MM-dd");

        private Maticsoft.Model.UserInfo user = new Maticsoft.Model.UserInfo();
        private Maticsoft.BLL.UserInfo userlist = new Maticsoft.BLL.UserInfo();
        protected string zuo = DateTime.Now.AddDays(-1.0).ToString("yyyy-MM-dd");

        protected void AspNetPager2_PageChanging(object src, PageChangingEventArgs e)
        {
            this.sql = string.Concat(new object[] { this.sql, " and  Id not in(select top ", (e.NewPageIndex - 1) * this.index, " Id from [Order] where ", this.sql, " order by Id desc ) " });
            try
            {
                this.getValue(this.index, 10, this.sql);
            }
            catch (Exception)
            {
                this.SetError("您填写的时间格式有错误,请重新填写");
            }
        }

        private void getName()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("<tr >");
            builder.Append("<td width='40'>ID</td>");
            builder.Append("<td width='300'>项目名称</td>");
            builder.Append("<td width='100'>用户</td>");
            builder.Append("<td width='300'>来源地址</td>");
            builder.Append("<td width='40'>详情</td>");
            builder.Append("</tr>");
            this.Literal1.Text = builder.ToString();
        }

        private void getState()
        {
            if (this.Session["value"] == null)
            {
                this.sql = this.sql ?? "";
            }
            else
            {
                this.sql = this.Session["value"].ToString();
                if ((((this.Session["zuo"] != null) && (this.Session["today"] != null)) && (this.Session["zuo"].ToString() != "")) && (this.Session["today"].ToString() != ""))
                {
                    this.zuo = this.Session["zuo"].ToString();
                    this.today = this.Session["today"].ToString();
                }
            }
        }

        private void getValue(int index, int page, string str)
        {
            StringBuilder builder = new StringBuilder();
            int num = 0;
            foreach (Maticsoft.Model.Order order in this.orderlist.GetList(index, 50, str))
            {
                if ((num % 2) != 0)
                {
                    builder.Append("<tr>");
                }
                else
                {
                    builder.Append("<tr class='alt'>");
                }
                num++;
                builder.Append("<td>" + order.Id + "</td>");
                this.team = this.teamlist.GetModel(order.Team_id);
                if ((this.team != null) && (this.team.Title.ToString() != ""))
                {
                    builder.Append(string.Concat(new object[] { "<td><a class='deal-title' href='../team.aspx?id=", this.team.Id, "' target='_blank'>", this.team.Title, "</a></td>" }));
                }
                else
                {
                    this.detaillist = this.detailbll.Searchorderdetail(order.Id);
                    builder.Append("<td>&nbsp;");
                    int num2 = 0;
                    foreach (Maticsoft.Model.orderdetail orderdetail in this.detaillist)
                    {
                        num2++;
                        builder.Append(string.Concat(new object[] { "(<a class='deal-title' href='../team.aspx?id=", orderdetail.Teamid, "' target='_blank'>", num2, ":" }));
                        builder.Append((this.teamlist.GetModel(Convert.ToInt32(orderdetail.Teamid)) == null) ? "" : this.teamlist.GetModel(Convert.ToInt32(orderdetail.Teamid)).Title);
                        builder.Append("</a>)<br>");
                    }
                    builder.Append("</td>");
                }
                this.user = this.userlist.GetModel(order.User_id);
                if ((this.user != null) && (this.user.Username != ""))
                {
                    builder.Append(string.Concat(new object[] { "<td><a class='ajaxlink' href='/ajax/manage.aspx?action=userview&Id=", this.user.Id, "'>", this.user.Username, "</a><br/>(", this.user.Email, ")</td>" }));
                }
                else if ((this.user != null) && (this.user.Email != ""))
                {
                    builder.Append("<td>" + this.user.Username + "<br/>(" + this.user.Email + ")</td>");
                }
                else
                {
                    builder.Append("<td>&nbsp;</td>");
                }
                if (order.Ip_Address != "")
                {
                    if (order.Ip_Address.Trim() == "直接输入网址")
                    {
                        builder.Append("<td style='color:red;'>直接输入网址</td>");
                    }
                    else
                    {
                        builder.Append("<td style='color:red;'><a target='_blank' href='" + order.Ip_Address + "' alt='" + order.Ip_Address + "'>" + order.Ip_Address + "</a></td>");
                    }
                }
                else
                {
                    builder.Append("<td>&nbsp;</td>");
                }
                builder.Append(string.Concat(new object[] { "<td class='op' nowrap><a href='/ajax/manage.aspx?action=orderview&orderview=", order.Id, "&pagenum=", this.pagenum, "' class='ajaxlink'>详情</a></td>" }));
                builder.Append("</tr>");
            }
            this.Literal2.Text = builder.ToString();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.HeaderControl1.Select = "tongji";
            if (base.Request["pagenum"] != null)
            {
                if (Utility.IsNum(base.Request["pagenum"].ToString()))
                {
                    this.pagenum = Convert.ToInt32(base.Request["pagenum"]);
                }
                else
                {
                    this.SetError("友情提示：参数非法");
                }
            }
            this.getName();
            if (!base.IsPostBack)
            {
                this.sql = this.sql ?? "";
                if (((this.Session["zuo"] != null) && (this.Session["today"] != null)) && (this.Session["value"] != null))
                {
                    this.Session.Remove("zuo");
                    this.Session.Remove("today");
                    this.Session.Remove("value");
                }
            }
            else if (base.Request.HttpMethod == "POST")
            {
                this.setState();
                this.getState();
            }
            try
            {
                this.getValue(this.index, 10, this.sql);
                this.pageSum(this.sql, this.index);
            }
            catch (Exception)
            {
                this.SetError("您填写的时间格式有错误,请重新填写");
            }
        }

        private void pageSum(string where, int count)
        {
            this.AspNetPager2.AlwaysShow = true;
            this.AspNetPager2.CurrentPageIndex = 1;
            this.AspNetPager2.PageSize = count;
            this.AspNetPager2.RecordCount = this.orderlist.GetModelList(where).Count;
            this.AspNetPager2.DataBind();
        }

        private void setState()
        {
            string sql;
            if ((base.Request.Form["today"] != null) && (base.Request.Form["today"].ToString() != ""))
            {
                sql = this.sql;
                this.sql = sql + " and Pay_time between '" + this.today + "' and '" + this.Tommorew + "'  ";
                this.Session.Add("value", this.sql);
                this.Session.Add("zuo", this.zuo);
            }
            if ((base.Request.Form["beforeDay"] != null) && (base.Request.Form["beforeDay"].ToString() != ""))
            {
                sql = this.sql;
                this.sql = sql + " and Pay_time between '" + this.zuo + "' and '" + this.today + "'  ";
                this.Session.Add("value", this.sql);
                this.Session.Add("today", this.today);
            }
            if ((((base.Request.Form["search"] != null) && (base.Request.Form["before"] != null)) && ((base.Request.Form["last"] != null) && (base.Request.Form["before"].ToString() != ""))) && (base.Request.Form["last"].ToString() != ""))
            {
                sql = this.sql;
                this.sql = sql + " and Pay_time between '" + base.Request.Form["before"].ToString() + " 00:00:01' and '" + base.Request.Form["last"].ToString() + " 23:59:59' ";
                this.Session.Add("value", this.sql);
                this.Session.Add("zuo", base.Request.Form["before"].ToString());
                this.Session.Add("today", base.Request.Form["last"].ToString());
            }
        }
    }


